//
//  BaseTableViewController.swift
//  WBDemo
//
//  Created by Meng on 16/12/16.
//  Copyright © 2016年 demo. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {
    
    /// 是否登录
    let isLogin = UserAccount.isLogin()
    
    var visitorView : VisitorView?
    
    
    override func loadView() {
        
        return isLogin ? super.loadView() : setVisitorView()
    }
    
    func setVisitorView() {
        visitorView = VisitorView.vistitorView()
//        visitorView?.delegate = self
        visitorView?.registerButton.addTarget(self, action: #selector(clickRegisterButton), for: .touchUpInside)
        visitorView?.loginButton.addTarget(self, action: #selector(clickLoginButton), for: .touchUpInside)
        
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(title: "注册", style: .plain, target: self, action: #selector(clickRegisterButton))
        navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "登录", style: .plain, target: self, action: #selector(clickLoginButton))
        
        view = visitorView
    }
    
    func clickRegisterButton() {
        MYLog("")
    }
    
    func clickLoginButton() {
        let sb = UIStoryboard(name: "OAuth", bundle: nil)
        guard let oauthvc = sb.instantiateInitialViewController() else {
            return
        }
        present(oauthvc, animated: true, completion: nil)
    }

}

extension BaseTableViewController : VisitorViewDelegate {
    
    func visitorViewDidRegisterButton(visitorView: VisitorView) {
        MYLog("")
    }
    
    func visitorViewDidLoginButton(visitorView: VisitorView) {
        MYLog("")
    }
    
}
